﻿Imports NHibernate
Namespace dal.dao
    Public MustInherit Class GenericNHibernateDAO(Of C As Class, ID)
        Implements genericDAO(Of C, ID)

        Protected session As ISession


        Public Function FindByID(ByVal id As ID) As C Implements genericDAO(Of C, ID).FindByID
            Return session.Load(Of C)(id)
        End Function
        Public Function FindAll() As IList(Of C) Implements genericDAO(Of C, ID).FindAll
            Return session.CreateCriteria(Of C).List(Of C)()
        End Function

        Public Function SaveOrUpdate(ByRef entity As C) As C Implements genericDAO(Of C, ID).SaveOrUpdate
            session.SaveOrUpdate(entity)
            Return entity
        End Function

        Public Function Delete(ByRef entity As C) As C Implements genericDAO(Of C, ID).Delete
            session.Delete(entity)
            Return entity
        End Function

        Public Function Lock(ByRef entity As C) As C Implements genericDAO(Of C, ID).lock
            session.Lock(entity, LockMode.None)
            Return entity
        End Function

        Public Sub New(ByRef session As ISession)
            Me.session = session
        End Sub

        Protected Sub New()

        End Sub
    End Class
End Namespace
